<template>
  <div id="Swiper">
      <!-- 只有当真正数据创建的时候我才会创建swiper，所有这里用v-if去解决问题 -->
  	  <swiper :options="swiperOption" v-if="showSwiper">
    	    <!-- slides -->
    	    <swiper-slide v-for="item,index of swiperList" :key="item.id">
  			       <img :src="item.imgUrl" class="swiper-img"/>
    	    </swiper-slide>
    	    <!-- Optional controls -->
    	    <div class="swiper-pagination" slot="pagination"></div>
  	  </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props:{
    swiperList:Array
  },
  data(){
  	return {
  		swiperOption:{
  			pagination:'.swiper-pagination',
  			loop:true,
        autoplay:3000
  		}
  	}
  },
  computed:{
    showSwiper(){
      return this.swiperList.length
    }
  }
}
</script>

<style scoped>
/*对swiper的轮播小圆点进行配置，使用>>>进行样式穿透*/
#Swiper >>> .swiper-pagination-bullet-active{
	background-color: #fff !important;
}
/*以图片的宽高比，图片的高度除以宽度就是固定的宽高比*/
/*这里的图片是640*200，200/640 = 31.25%*/
#Swiper{
	width: 100%;
	height: 0;
	overflow: hidden;
	padding-bottom: 31.25%;
	background-color: #eee;
}
.swiper-img{
	width: 100%;
	height:2.5rem;
}

</style>